/****************************************
 ****************************************
 **   This document written by CTonk.  **
 **         ctonk@hotmail.com          **
 ****************************************
 ****************************************/

// colors.cpp

#ifndef CPP_COLORS
#define CPP_COLORS

#include <iostream>
#include <Windows.h>

void cprint( char* );
void cprint( std::string );

#define ccb SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ),  1 )
#define ccg SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ),  2 )
#define ccc SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ),  3 )
#define ccr SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ),  4 )
#define ccm SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ),  5 )
#define ccy SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ),  6 )
#define ccx SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ),  7 )
#define ccw SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ),  8 )
#define ccB SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ),  9 )
#define ccG SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 10 )
#define ccC SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 11 )
#define ccR SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 12 )
#define ccM SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 13 )
#define ccY SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 14 )
#define ccW SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 15 )

void cprint( char* stuff )
{
	for ( int x=0; x < (int)strlen(stuff); x++ )
		if ( stuff[x] == '{' )
		{
			switch ( stuff[x+1] )
			{
				case 'b': SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ),  1 ); break;
				case 'g': SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ),  2 ); break;
				case 'c': SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ),  3 ); break;
				case 'r': SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ),  4 ); break;
				case 'm': SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ),  5 ); break;
				case 'y': SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ),  6 ); break;
				case 'w': SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ),  8 ); break;
				case 'B': SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ),  9 ); break;
				case 'G': SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 10 ); break;
				case 'C': SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 11 ); break;
				case 'R': SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 12 ); break;
				case 'M': SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 13 ); break;
				case 'Y': SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 14 ); break;
				case 'W': SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 15 ); break;
				default:  SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ),  7 );
			}
			x++;
		}
		else
			std::cout << stuff[x];

	SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ),  7 );
	return;
}

void cprint( std::string stuff )
{
	for ( unsigned int x=0; x < stuff.length(); x++ )
		if ( stuff[x] == '{' )
		{
			switch ( stuff[x+1] )
			{
				case 'b': SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ),  1 ); break;
				case 'g': SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ),  2 ); break;
				case 'c': SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ),  3 ); break;
				case 'r': SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ),  4 ); break;
				case 'm': SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ),  5 ); break;
				case 'y': SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ),  6 ); break;
				case 'w': SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ),  8 ); break;
				case 'B': SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ),  9 ); break;
				case 'G': SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 10 ); break;
				case 'C': SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 11 ); break;
				case 'R': SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 12 ); break;
				case 'M': SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 13 ); break;
				case 'Y': SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 14 ); break;
				case 'W': SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 15 ); break;
				default:  SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ),  7 );
			}
			x++;
		}
		else
			std::cout << stuff[x];

	SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ),  7 );
	return;
}

//int main() { // This is kept here merely for ease of testing/debugging
//	return 0;
//}

#endif // #ifndef CPP_COLORS